package com.ssyc.main.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ssyc.common.base.BaseActivity;
import com.ssyc.common.http.HttpUtils;
import com.ssyc.common.manager.AccountUtils;
import com.ssyc.common.utils.GsonUtil;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.common.view.dialog.CustomDialogManager;
import com.ssyc.main.R;
import com.ssyc.main.bean.AboutUsInfo;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;


/**
 * 通用的关于我们界面
 * Created by Administrator on 2019/5/5 0005.
 */

@Route(path = "/main/AboutUsActivity")
public class AboutUsActivity extends BaseActivity {
    ImageView ivBack;
    TextView tvContent;
    TextView tvEmail;
    TextView tvTel;
    ImageView lvCode;
    TextView tvName;
    LinearLayout llContent;

    //学校的相关信息
    private String app_content, app_url, app_email, app_phone;


    //页面更新的标识
    public static final int UPDATE = 0x870;

    @Override
    protected int getContentLayout() {
        return R.layout.main_activity_about_us;
    }

    @Override
    protected void init() {

        //显示内容
        showContent();

        //初始化视图
        initView();

        //请求服务器
//        http();
    }

    /**
     * 初始化视图
     */
    private void initView() {
        ivBack = findViewById(R.id.iv_back);
//        tvContent = findViewById(R.id.tv_content);
//        tvEmail = findViewById(R.id.tv_email);
//        tvTel = findViewById(R.id.tv_tel);
//        lvCode = findViewById(R.id.lv_code);
//        tvName = findViewById(R.id.tv_name);
//        lvCode = findViewById(R.id.lv_code);
        llContent = findViewById(R.id.ll_content);
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isDoubleClick(v)) {
                    //返回
                    finish();
                }
            }
        });

    }


    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    /**
     * 请求服务器的方法
     */
    private void http() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "1");
        map.put("acc", AccountUtils.getAccount(this));
        map.put("role", AccountUtils.getRole(this));
        map.put("school", AccountUtils.getSchoolId(this));
        map.put("platform", "2");
//        LogUtils.iTag("test", HttpAddress.ABOUTUS + "?platform=2&type=1&acc=" + AccountUtils.getAccount(this)
//                + "&role=" + AccountUtils.getRole(this) + "&school=" + AccountUtils.getSchoolId(this));
        HttpUtils.post("", map, this, new HttpUtils.CallBack() {
            @Override
            public void onError(Call call, Exception e, int id) {
                //请求失败
                CustomDialogManager.dissmiss();
                UiUtils.Toast("网络错误", false);
            }

            @Override
            public void onResponse(String response, int id) {
                //解析数据
                AboutUsInfo info = GsonUtil.jsonToBean(response, AboutUsInfo.class);
            }
        });

    }

    /**
     * 设置页面数据
     *
     * @param info
     */
//    public void setPageData(AboutUsInfo info) {
//        app_content = info.getApp_content();
//        app_email = info.getApp_email();
//        app_phone = info.getApp_phone();
//        app_url = info.getApp_url();
//        //内容
//        if (!TextUtils.isEmpty(info.getApp_content())) {
//            tvContent.setText(info.getApp_content().replace("\\n", "\n"));
//
//        } else {
////            tvContent.setText(getResources().getString(R.string.ycsjcontent).replace("\\n", "\n"));
//        }
//
//        //邮箱
//        if (!TextUtils.isEmpty(info.getApp_email())) {
//            tvEmail.setText(info.getApp_email());
//        } else {
//            tvEmail.setText(getResources().getString(R.string.ycsjemail));
//        }
//
//        //电话
//        if (!TextUtils.isEmpty(info.getApp_phone())) {
//            tvTel.setText(info.getApp_phone());
//        } else {
//            tvTel.setText(getResources().getString(R.string.ycsjtel));
//        }
//
//        //二维码
//        if (!TextUtils.isEmpty(info.getApp_qrcode())) {
//            ImageUtil.displayImage(this, lvCode, info.getApp_qrcode());
//        } else {
//            lvCode.setImageResource(R.drawable.yingcaishijia);
//        }
//
//        //名称
//        if (!TextUtils.isEmpty(info.getSchool_name())) {
//            tvName.setText(info.getSchool_name());
//        } else {
//            tvName.setText(getResources().getString(R.string.ycsjname));
//        }
//
//    }


//    /**
//     * 事件处理
//     *
//     * @param busInfo
//     */
//    @Override
//    public void busEvent(BusInfo busInfo) {
//        super.busEvent(busInfo);
//        if (null != busInfo && UPDATE == busInfo.type) {
//            http();
//        }
//    }
}
